package com.shujia

object Demo25Match {
  def main(args: Array[String]): Unit = {


    val list: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)


    /**
      * 奇数偶数分开处理
      * 奇数加1  偶数加2
      *
      */


    list.map(i => {
      if (i % 2 == 0) {
        i + 2
      } else {
        i + 1
      }
    }).foreach(println)


    list.map(i => i % 2 match {
      case 0 => i + 2
      case 1 => i + 1
    }).foreach(println)


    val list1: List[Any] = List(1, 2, 3, 4, 5, 6, 7, 8, "java")


    println("=" * 100)


    list1.map(o => o match {
      case i: Int => i
      case s: String => 0
    }).foreach(println)



    //简写
    list1.map {
      case i: Int => i
      case s: String => 0
    }.foreach(println)





  }

}
